using System.Windows.Media;
using HQLAddin.Intellisense;
using HqlIntellisense;
using Microsoft.VisualStudio.Language.Intellisense;
using Moq;
using NUnit.Framework;
using SharpTestsEx;

namespace HQLAddin.Tests.Intellisense
{
	[TestFixture]
	public class DeclarationTests
	{
		[Test]
		public void WhenCompletionProposalIsEntityThenDisplayEntityName()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.EntityName, 0)
			{
				SimpleName = "Foo"
			};

			var declaration = new HqlCompletion(hqlCompletionProposal, null);
			declaration.DisplayText.Should().Be.EqualTo("Foo");
		}

		[Test]
		public void WhenCompletionProposalIsEntityThenNameIsEqualToEntityName()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.EntityName, 0)
			{
				SimpleName = "Foo"
			};

			var declaration = new HqlCompletion(hqlCompletionProposal, null);
			declaration.InsertionText.Should().Be.EqualTo("Foo");
		}

		[Test]
		public void WhenCompletionProposalIsFunctionThenDisplayTextIsSimpleName()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.Function, 0)
			                            	{
			                            		SimpleName = "abs"

			                            	};

			var declaration = new HqlCompletion(hqlCompletionProposal, null);
			declaration.DisplayText.Should().Be.EqualTo("abs");
		}

		[Test]
		public void WhenCompletionProposalIsFunctionThenDisplayTextIsSimpleNamePlusLeftParenthesis()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.Function, 0){ SimpleName = "abs" };

			var declaration = new HqlCompletion(hqlCompletionProposal, null);
			declaration.InsertionText.Should().Be.EqualTo("abs(");
		}

		//[Test]
		//public void WhenCompletionProposalIsFunctionThenGlyphIsFunction()
		//{
		//    var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.Function, 0)
		//    {
		//        SimpleName = "abs"

		//    };

		//    var declaration = new Declaration(hqlCompletionProposal);
		//    declaration.Glyph.Should().Be.EqualTo(Declaration.FunctionGlyph);
		//}
		
		[Test]
		public void DisplayTextForKeyWordShouldBeEqualToCompletion()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.EntityName, 0);
			hqlCompletionProposal.CompletionKind = CompletionKind.KeyWord;
			hqlCompletionProposal.Completion = "where";

			var declaration = new HqlCompletion(hqlCompletionProposal, null);
			declaration.DisplayText.Should().Be.EqualTo("where");
		}

		[Test]
		public void CompletionNameForKeyWordShouldBeEqualToCompletion()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.EntityName, 0);
			hqlCompletionProposal.CompletionKind = CompletionKind.KeyWord;
			hqlCompletionProposal.Completion = "where";

			var declaration = new HqlCompletion(hqlCompletionProposal, null);
			declaration.InsertionText.Should().Be.EqualTo("where");
		}


		[Test]
		public void WhenCompletionKindIsEntityThenReturnTheImageSourceOfClass()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.EntityName, 0);
			hqlCompletionProposal.CompletionKind = CompletionKind.EntityName;
			hqlCompletionProposal.Completion = "Foo";


			var imageSource = new DrawingImage();
			var glyphService = new Mock<IGlyphService>();
			glyphService.Setup(gs => gs.GetGlyph(StandardGlyphGroup.GlyphGroupClass, StandardGlyphItem.GlyphItemPublic))
				.Returns(imageSource);

			var completion = new HqlCompletion(hqlCompletionProposal, glyphService.Object);
			completion.IconSource.Should().Be.SameInstanceAs(imageSource);
		}

		[Test]
		public void WhenCompletionKindIsPropertyThenReturnTheImageSourceOfProperty()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.Property, 0);
			hqlCompletionProposal.CompletionKind = CompletionKind.Property;
			hqlCompletionProposal.Completion = "Foo";


			var imageSource = new DrawingImage();
			var glyphService = new Mock<IGlyphService>();
			glyphService.Setup(gs => gs.GetGlyph(StandardGlyphGroup.GlyphGroupProperty, StandardGlyphItem.GlyphItemPublic))
				.Returns(imageSource);

			var completion = new HqlCompletion(hqlCompletionProposal, glyphService.Object);
			completion.IconSource.Should().Be.SameInstanceAs(imageSource);
		}

		[Test]
		public void WhenCompletionKindIsFunctionThenReturnTheImageSourceOfMethod()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.Property, 0);
			hqlCompletionProposal.CompletionKind = CompletionKind.Function;
			hqlCompletionProposal.Completion = "Foo";


			var imageSource = new DrawingImage();
			var glyphService = new Mock<IGlyphService>();
			glyphService.Setup(gs => gs.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic))
				.Returns(imageSource);

			var completion = new HqlCompletion(hqlCompletionProposal, glyphService.Object);
			completion.IconSource.Should().Be.SameInstanceAs(imageSource);
		}


		[Test]
		public void WhenCompletionKindIsAliasRefThenReturnTheImageSourceOfPrivateVariable()
		{
			var hqlCompletionProposal = new HQLCompletionProposal(CompletionKind.Property, 0);
			hqlCompletionProposal.CompletionKind = CompletionKind.AliasRef;
			hqlCompletionProposal.Completion = "Foo";

			var imageSource = new DrawingImage();
			var glyphService = new Mock<IGlyphService>();
			glyphService.Setup(gs => gs.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPrivate))
				.Returns(imageSource);

			var completion = new HqlCompletion(hqlCompletionProposal, glyphService.Object);
			completion.IconSource.Should().Be.SameInstanceAs(imageSource);
		}
	}
}